<template>
  <div class="calendar-bottom">
    <div class="left">
      <h2>{{ result.lunar }}</h2>
      <h3>{{ result.lunarYear }}年 {{ result.animalsYear }}</h3>
    </div>
    <div class="right">
      <div>
        <span class="suit">宜</span>
        <span>{{ result.suit }}</span>
      </div>
      <div>
        <span class="avoid">宜</span>
        <span> {{ result.avoid }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useCounterStore } from '@/stores/calendar'

const { formatDate } = storeToRefs(useCounterStore())
import axios from 'axios'

const key = 'e3c654f274663b03b8eed73aeecdb729'
const res = await axios.get(`/calendar/day?date=${formatDate.value}&key=${key}`)

const result = ref(res.data.result.data)
//监听,如果日期改变,就重新请求数据
watch(formatDate, async () => {
  const res = await axios.get(
    `/calendar/day?date=${formatDate.value}&key=${key}`
  )
  result.value = res.data.result.data
})
</script>

<style lang="scss" scoped>
.calendar-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 16px;
  .left {
    flex: 1;
  }
  .right {
    flex: 3;
    span {
      font-size: 14px;
      margin-left: 8px;
    }
    .suit {
      color: #fff;
      background: #f33;
      padding: 1px 3px;
      font-size: 12px;
      // line-height: 14px;
      border-radius: 4px;
    }
    .avoid {
      color: #fff;
      background: #333;
      padding: 1px 3px;
      font-size: 12px;
      border-radius: 4px;
    }
  }
}
</style>